package com.thoughtworks.twu.module1;

public final class DiamondExercises {
    private DiamondExercises() {

    }

    public static void run() {
        printIsoscelesTriangle(3);
        printDiamond(3);
        printDiamondWithName(4);
    }

    private static void printTriangleLine(int triangleSize, int lineNumber) {
        Utilities.printMultipleSpaces(triangleSize - lineNumber);
        Utilities.printMultipleAsterisks(2*lineNumber - 1);
        System.out.println();
    }

    private static void printIsoscelesTriangle(int n) {
        Utilities.printTitle(String.format("Draw an isosceles triangle (with n = %d)", n));

        for (int i = 1; i <= n; i++) {
            printTriangleLine(n, i);
        }
    }

    private static void printDiamond(int n, boolean printName) {
        for (int i = 1; i < n; i++) {
            printTriangleLine(n, i);
        }

        if (printName) {
            // It's not clear if the exercise wants us to center the name in the diamond, or just print our name in place
            // of the line of spaces and asterisks... I've chosen the latter because it's easier to implement.
            System.out.println("Charles");
        } else {
            printTriangleLine(n, n);
        }

        for (int i = n - 1; i > 0; i--) {
            printTriangleLine(n, i);
        }
    }

    private static void printDiamond(int n) {
        Utilities.printTitle(String.format("Draw a diamond (with n = %d)", n));
        printDiamond(n, false);
    }

    private static void printDiamondWithName(int n) {
        Utilities.printTitle(String.format("Draw a diamond with my name in the middle (with n = %d)", n));
        printDiamond(n, true);
    }
}
